$(function () {
    var ajax = new ajaxpage();
    let host = window.location.host;
    ajax.init(host);
})
var ajaxpage = function () {
    var self = this;
    this.init = function (host) {
        // 搜索
        $("button.searchBtn").unbind("click").click(function () {
            var keyword = document.getElementById("keyword").value;
            if (keyword) {
                keyword = keyword.replace(/ /g, '');
                var url = "/index/search/results/keyword/" + keyword;
                window.location.href = url;
            }
        })
        $("li.apart_one_nav").unbind("click").click(function () {
            var index = $(this).index();
            $(".apart_one").eq(index).removeClass("ahidden").siblings(".apart_one").addClass("ahidden");
            $(this).addClass("sharetitle_active").siblings("").removeClass("sharetitle_active");
        })

        $("li.apart_two_nav").unbind("click").click(function () {
            var index = $(this).index();
            $(".apart_two").eq(index).removeClass("ahidden").siblings(".apart_two").addClass("ahidden");
            $(this).addClass("sharetitle_active").siblings("").removeClass("sharetitle_active");
        })

        $("li.scate").unbind("cilck").click(function () {
            let category_by = $(this).attr("setcategory_by");
            let nid = $(this).attr("setnid");
            // 获取上级栏目model
            if (category_by || category_by == "0") {
                let data = { category_by: category_by, nid: nid };
                $.ajax({
                    type: 'post',
                    url: "/index/rou/model_response",
                    data: data,
                    dataType: 'json',
                    success: function (ret) {
                        // console.log(ret);
                        if (ret.code == 5000) {
                            let modelName = ret.msg.model;
                            let url = '';
                            if (category_by == "0") {
                                url = "/index/" + modelName + "/index/nid/" + nid;
                            } else {
                                url = "/index/" + modelName + "/index/nid/" + nid + "/category_by/" + category_by;
                            }
                            window.location.href = url;
                        }
                    },
                    error: function () {
                        console.log("请求异常");
                    }
                })
            }
        })
    }
}